package com.cms.doc.service.impl;

import java.util.List;

import com.cms.doc.model.DocText;
import com.cms.doc.service.DocTextService;
import com.jframe.sys.orm.service.impl.BaseServiceImpl;
import com.jframe.sys.orm.utils.ResultSet;

public class DocTextServiceImpl extends BaseServiceImpl<DocText> implements DocTextService {

	@Override
	public boolean toTop(int id, String isTop) {
		String hql = " update DocText set istop = ? where id = ?";
		this.dao.execute(hql, new Object[]{isTop,id});
		return true;		
	}

	@Override
	public boolean setStatus(String ids, String status) {
		// TODO Auto-generated method stub
		List<DocText> list = this.findListByIds(ids);
		for(DocText docText:list){
			docText.setStatus(status);
			this.save(docText);
		}
		return true;
	}

	@Override
	public ResultSet<DocText> findListByTypeIds(String ids, int start, int limit) {
		// TODO Auto-generated method stub
		String hql = "from DocText where status='2' and typeId in (:ids) order by isTop,updateTime desc";
		ResultSet<DocText> rs = new ResultSet<DocText>();
		rs.setRows(this.dao.findByIds(hql, ids, start, limit));
		rs.setTotal(this.dao.queryForIntByHql(hql.toString(), ids));
		return rs;
	}

	@Override
	public DocText readDocText(String id) {
		// TODO Auto-generated method stub
		DocText doc = this.load(id);
		doc.setVisitNum(doc.getVisitNum()+1);
		return doc;
	}
	

	
}
